package com.juzipi.demo.controller;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("error")
public class TestErrorController implements ErrorController {

    @Override
    public String getErrorPath() {
        return null;
    }

    //添加url映射指向error
    @RequestMapping
    public Map<String,Object> handlerError(){
        //用map容器返回信息
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code",404);
        hashMap.put("msg","不存在");
        return hashMap;

    }


    @RequestMapping("ok")
    @ResponseBody
    public Map<String,Object> noError(){
        //用map容器返回信息
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code",200);
        hashMap.put("msg","成功");
        return hashMap;



    }

}
